Mysql5.7 编译安装
========================================

优秀文章推荐：  
    http://www.linuxidc.com/Linux/2017-02/140424.htm
    http://blog.csdn.net/zilong00007/article/details/55670722


一：准备

1.1：源码下载
        mysql 官网：http://dev.mysql.com/downloads/mysql/
        ~]# yum -y install gcc gcc-c++ bzip2 bzip2-devel bzip2-libs python-devel
        boost下载： http://www.boost.org/users/download/
        ~]# 安装： http://blog.csdn.net/zgl_dm/article/details/8363843

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql_57 

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql_57 \
-DEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all
        
1.2：安装依赖
      ~]# yum -y install perl perl-devel autoconf cmake gcc gcc-c++ ncurses ncurses-devel boost* bison libgcrypt wget
      ~]# wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

1.3：备注
    -DCMAKE_INSTALL_PREFIX= 安装主目录
    -DSYSCONFDIR= 配置文件安装位置
    -DMYSQL_DATADIR= 数据目录

wget -c "https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz" -O boost_1_66_0.tar.gz



二：编译安装

2.1：编译初始目录
  ~]# mkdir -pv /web/mysql_57
  ~]# chmod -R 777 /web/mysql_57

2.2；编译
    ~]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc/mysql -DMYSQL_DATADIR=/data/mysql/data
    ~]# make && make install



cmake . -DCMAKE_INSTALL_PREFIX=/web/mysql_57 \
-DEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all

cmake . -DCMAKE_INSTALL_PREFIX=/web/mysql_57 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/include/boost \
-DEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all

cmake . -DCMAKE_INSTALL_PREFIX=/web/mysql_57 \
-DEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all


    -DCMAKE_INSTALL_PREFIX=/home/nick/mysql     /
    -DMYSQL_UNIX_ADDR=/home/nick/mysql/mysql.sock /
    -DDEFAULT_CHARSET=utf8 /
    -DDEFAULT_COLLATION=utf8_general_ci /
    -DWITH_INNOBASE_STORAGE_ENGINE=1 /
    -DWITH_ARCHIVE_STORAGE_ENGINE=1 /
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 /
    -DMYSQL_DATADIR=/home/nick/mysql/data /
    -DMYSQL_TCP_PORT=3306 
    -DWITH_BOOST=boost 

/usr/include/boost





make -j 4 && make install

-DCMAKE_INSTALL_PREFIX ：安装路径
-DMYSQL_DATADIR ：数据存放目录
-DWITH_BOOST ：boost源码路径
-DSYSCONFDIR ：my.cnf配置文件目录
-DEFAULT_CHARSET ：数据库默认字符编码
-DDEFAULT_COLLATION ：默认排序规则
-DENABLED_LOCAL_INFILE ：允许从本文件导入数据
-DEXTRA_CHARSETS ：安装所有字符集


2.3：配置文件
  ~]# cp /usr/local/mysql/support-files/my-default.cnf /etc/mysql/my.cnf
  ~]# vim /etc/mysql/my.cnf
------------------------------------------------------------------------------------------------
[mysqld]
# innodb_buffer_pool_size = 128M

# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
# server_id = .....
socket = /tmp/mysql.sock

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 
skip_name_resolve=on
innodb_file_per_table=on

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]
log-error=/var/log/mysql/mysql.log
pid-file=/var/run/mysql/mysql.pid
------------------------------------------------------------------------------------------------


2.4：加入系统启动
    ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    ~]# chkconfig --add mysqld
    ~]# chkconfig --list mysqld

2.5：初始化
    ~]#  /usr/local/mysql/scripts/mysql_install_db  --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/


2.6：加入环境变量
    ~]# echo 'export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/sbin/' >  /etc/profile.d/mysql.sh
    ~]# source  /etc/profile.d/mysql.sh

2.7：修改所属用户与组
  ~]# chown -R mysql:mysql  /usr/local/mysql

2.8：启动 停止与重启
  ~]# service mysqld (start | restart | stop)

2.9：进入mysql客户端
  ~]# mysql


三：用户授权
3.1：授权（172.0.0.1   localhost   远程     需要分别授权）
    grant all privileges on *.* to '用户名'@'允许的主机' identified by '密码' with grant option;
    flush privileges;


     grant all privileges on *.* to 'mysql'@'127.0.0.1' identified by '123456' with grant option;
     grant all privileges on *.* to 'mysql'@'localhost' identified by '123456' with grant option;
     grant all privileges on *.* to 'mysql'@'%' identified by '123456' with grant option;
     flush privileges;

mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES;



